﻿using UnityEngine;
using UnityEngine.UI;
using System;

public class TimeController : MonoBehaviour {
	
	public int beginTime = 0;    //开始时间
	public int timeSpeed = 1;
	public int hour2min = 60; 
	public int min2second = 60;
	public Text timeText;
    public Light sun;

	private double nowTime; //当前时间
	private GeneralTime generalTime;

	void Start () {
		generalTime = new GeneralTime ();
        TimeSpan ts = DateTime.UtcNow - new DateTime(1970, 1, 1, 0, 0, 0, 0);
        generalTime.nowDate = Convert.ToInt64(ts.TotalSeconds) + beginTime;
        sun.transform.Rotate(Vector3.right * -80, Space.World);
    }

	void Update () {
		generalTime.nowDate += timeSpeed * Time.deltaTime;
		timeText.text = "Time:" + generalTime.GetFormatNowTime();

        float rotation = Time.deltaTime * 50;
        sun.transform.Rotate(Vector3.forward * rotation, Space.World);
    }

    /// <summary>
    /// 设置阳光照射角度
    /// </summary>
    /// <param name="nowTime">当前时间</param>
    void SetLightRotation(int nowTime)
    {
        float angle = nowTime;
        sun.transform.rotation = Quaternion.Euler(new Vector3(nowTime, 90, 60));
    }
}
